Skip to content

fix: isolate /run with tmpfs and recreate /var/run symlinks in sandbox#54

Merged
tito merged 2 commits intomainfrom
mathieu/fix-var-run-symlinks
Mar 24, 2026
Merged

fix: isolate /run with tmpfs and recreate /var/run symlinks in sandbox#54
tito merged 2 commits intomainfrom
mathieu/fix-var-run-symlinks

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented Mar 24, 2026

Summary

This PR includes two fixes for /run handling in the Linux sandbox:

  1. Isolate /run with tmpfs to prevent sandbox escape (d1afb06) - Replace blanket --ro-bind /run with --tmpfs /run and selectively mount only what's needed. Previously, host sockets (Docker, Podman, containerd, libvirt) were accessible inside the sandbox, allowing full escape via Unix socket connections which bypass read-only mount restrictions.

  2. Recreate /var/run and /var/lock symlinks (d7b3404) - On modern Linux distros, /var/run -> /run and /var/lock -> /run/lock. Many programs (virsh, systemctl, etc.) hardcode /var/run paths and fail without these symlinks. Follows the same pattern already used for /bin -> usr/bin, /lib -> usr/lib, etc.

Fixes #55
Fixes #53

Test plan

  • ./greywall -- docker ps fails to connect (socket no longer exposed)
  • ./greywall -- ls /var/run/ resolves correctly inside sandbox
  • ./greywall -- virsh -c qemu:///system list connects successfully (with libvirt allowRead/allowWrite config)
  • make test passes
  • Verify on a distro where /var/run is a real directory (not a symlink) that no symlink is created

tito added 2 commits March 24, 2026 10:48
Previously, buildDenyByDefaultMounts bind-mounted the entire host /run
read-only, then overlaid /run/user with a tmpfs for D-Bus isolation.
This left host sockets (Docker, Podman, containerd, libvirt, etc.)
accessible inside the sandbox. Unix socket connections bypass
filesystem read-only restrictions, so any exposed socket with
matching permissions allowed full sandbox escape (e.g., docker run
with host filesystem mounts).

Replace the blanket --ro-bind /run /run with --tmpfs /run (allowlist
approach), selectively mounting only:
- /run/systemd/resolve/* when /etc/resolv.conf is a symlink into /run
- /run/user/<uid>/bus for the filtered D-Bus proxy socket

This matches the existing SSH key protection pattern (--ro-bind
/dev/null over sensitive files) but is more robust: unknown sockets
are excluded by default rather than requiring explicit deny rules.
On modern Linux distros, /var/run is a symlink to /run and /var/lock
is a symlink to /run/lock. Many programs (virsh, systemctl, etc.)
hardcode /var/run paths.

The sandbox already recreates symlinks for /bin, /sbin, /lib, /lib64
but was missing /var, causing programs to fail with "No such file or
directory" even when /run paths were correctly configured.

Fixes #53
@tito tito changed the title fix: recreate /var/run and /var/lock symlinks in sandbox fix: isolate /run with tmpfs and recreate /var/run symlinks in sandbox Mar 24, 2026
@tito tito merged commit d38a8db into main Mar 24, 2026
4 checks passed
@tito tito deleted the mathieu/fix-var-run-symlinks branch March 24, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant